package com.lbb.http.interceptor

import android.util.Log
import com.google.gson.Gson
import com.lbb.http.bean.ResultBean
import com.lbb.http.bean.ResultException

class GsonResultInterceptor : ResultInterceptor {
    val gson = Gson()
    override fun onResponse(string: String): String {
        Log.i("GsonInterceptor", "onResponse--->$string")
        val bean = gson.fromJson(string, ResultBean::class.java)
        if (bean.code == "0000") {
            return gson.toJson(bean.result)
        }
        throw  ResultException(bean.message)
    }

    override fun onFailure(string: String): String {
        Log.i("GsonInterceptor", "onFailure--->$string")
        return string
    }
}